<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button onclick="handleCilck()">login</button>
</body>
<script>
  function handleCilck() {
    var url = 'http://127.0.0.1:2500/login';
    var data = {
      username: '1',
      password: '1'
    };

    fetch(url, {
        method: 'POST', // or 'PUT'
        body: JSON.stringify(data), // data can be `string` or {object}!
        headers: new Headers({
          'Content-Type': 'application/json'
        })
      }).then(res => res.json())
      .catch(error => console.error('Error:', error))
      .then(response => {
        console.log('Success:', response)
        console.log("........");
        fetch('http://127.0.0.1:2500/test', {
            headers: new Headers({
              'authorization': response.token
            })
          })
          .then(res => res.json()).then(response => {
            console.log(response);
          })
          .catch(err => console.log('Error:', err))
      })

  }
</script>

</html>